package io.modifier.basic.compose.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp

interface FontSizeStyle {
    val default
        get() = TextStyle(
            fontFamily = FontFamily.Default,
            fontWeight = FontWeight.Normal, // 400
            fontSize = TextUnit.Unspecified,
            color = Color.Unspecified,
        )

    val head: TextStyle
        @Composable
        get() = default.size(20).weight(400).copy(AppThemeHolder.colors.txtColor)

    val title: TextStyle
        @Composable
        get() = default.size(16).weight(500).copy(AppThemeHolder.colors.txtColor)

    val content: TextStyle
        @Composable
        get() = default.size(13).weight(400).copy(AppThemeHolder.colors.txtColor)

    val btn: TextStyle
        @Composable
        get() = default.size(16).weight(400).copy(AppThemeHolder.colors.appColor)

    val desTitle: TextStyle
        @Composable
        get() = default.size(12).weight(400).copy(AppThemeHolder.colors.txtColor)

    val des: TextStyle
        @Composable
        get() = default.size(12).weight(400).copy(AppThemeHolder.colors.txtGray)

    val normal get() = TextStyle(fontWeight = FontWeight.Normal)

    val bold get() = TextStyle(fontWeight = FontWeight.Bold)

}

internal object DefaultFontSizeStyle : FontSizeStyle

@Composable
fun TextStyle.txtColor(): TextStyle = this.copy(color = MaterialTheme.appColors.txtColor)

@Composable
fun TextStyle.txtGray(): TextStyle = this.copy(color = MaterialTheme.appColors.txtGray)

@Composable
fun TextStyle.appColor(): TextStyle = this.copy(color = MaterialTheme.appColors.appColor)

@Composable
fun TextStyle.onAppColor(): TextStyle = this.copy(color = MaterialTheme.appColors.onAppColor)

@Composable
fun TextStyle.errorColor(): TextStyle = this.copy(color = MaterialTheme.appColors.error)

@Composable
fun TextStyle.successColor(): TextStyle = this.copy(color = MaterialTheme.appColors.success)

@Composable
fun TextStyle.bold(): TextStyle = this.copy(fontWeight = FontWeight.Bold)

@Composable
fun TextStyle.italic(): TextStyle = this.copy(fontStyle = FontStyle.Italic)

@Composable
fun TextStyle.normal(): TextStyle = this.copy(fontWeight = FontWeight.Normal)

@Composable
fun TextStyle.size(size: Int): TextStyle = this.copy(fontSize = size.sp)

@Composable
fun TextStyle.weight(weight: Int): TextStyle = this.copy(fontWeight = FontWeight(weight))

@Composable
fun TextStyle.color(c: Color): TextStyle = this.copy(color = c)

@Composable
fun TextStyle.surface(): TextStyle = this.copy(color = AppThemeHolder.colors.surface)

@Composable
fun TextStyle.customDarkColor(c: Color, darkColor: Color): TextStyle =
    this.copy(color = if (isSystemInDarkTheme()) darkColor else c)

val MaterialTheme.appTextStyle
    @Composable @ReadOnlyComposable get() = AppThemeHolder.textStyle


// Set of Material typography styles to start with
val Typography = Typography(
    bodyLarge = TextStyle(
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight.Normal,
        fontSize = 16.sp,
        lineHeight = 24.sp,
        letterSpacing = 0.5.sp
    )
    /* Other default text styles to override
    titleLarge = TextStyle(
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight.Normal,
        fontSize = 22.sp,
        lineHeight = 28.sp,
        letterSpacing = 0.sp
    ),
    labelSmall = TextStyle(
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight.Medium,
        fontSize = 11.sp,
        lineHeight = 16.sp,
        letterSpacing = 0.5.sp
    )
    */
)

/**
 *
 * 各种文本样式及其含义：
 *
 * displayLarge：最大的显示文本，通常用于突出显示重要信息或吸引注意力。
 * displayMedium：第二大的显示文本，也用于突出显示重要信息，但相对较小。
 * displaySmall：最小的显示文本，用于较小的标题或信息。
 * headlineLarge：最大的标题，用于突出显示短而重要的文本或数字，可以选择有表现力的字体。
 * headlineMedium：第二大的标题，用于突出显示短而重要的文本或数字，字体相对较小。
 * headlineSmall：最小的标题，用于突出显示短而重要的文本或数字，字体相对较小。
 * titleLarge：最大的标题，用于中等重要性的文本，长度较短。
 * titleMedium：第二大的标题，用于中等重要性的文本，长度较短。
 * titleSmall：最小的标题，用于中等重要性的文本，长度较短。
 * bodyLarge：最大的正文，用于长篇文章，适合小字体。
 * bodyMedium：第二大的正文，用于长篇文章，适合小字体。
 * bodySmall：最小的正文，用于长篇文章，适合小字体。
 * labelLarge：用于按钮、标签等，呼吁行动的较大文本。
 * labelMedium：较小的字体，用于标注图像或引入标题。
 * labelSmall：最小的字体，用于标注图像或引入标题。
 */
